package com.ruoyi.web.controller.yf;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.yf.domain.YfArchives;
import com.ruoyi.yf.service.IYfArchivesService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 医废档案资料管理Controller
 * 
 * @author XiaoYi...
 * @date 2021-09-17
 */
@Controller
@RequestMapping("/yf/archives")
public class YfArchivesController extends BaseController
{
    private String prefix = "yf/archives";

    @Autowired
    private IYfArchivesService yfArchivesService;

    @RequiresPermissions("yf:archives:view")
    @GetMapping()
    public String archives()
    {
        return prefix + "/archives";
    }

    /**
     * 查询医废档案资料管理列表
     */
    @RequiresPermissions("yf:archives:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YfArchives yfArchives)
    {
        startPage();
        List<YfArchives> list = yfArchivesService.selectYfArchivesList(yfArchives);
        return getDataTable(list);
    }

    /**
     * 导出医废档案资料管理列表
     */
    @RequiresPermissions("yf:archives:export")
    @Log(title = "医废档案资料管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YfArchives yfArchives)
    {
        List<YfArchives> list = yfArchivesService.selectYfArchivesList(yfArchives);
        ExcelUtil<YfArchives> util = new ExcelUtil<YfArchives>(YfArchives.class);
        return util.exportExcel(list, "archives");
    }

    /**
     * 新增医废档案资料管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存医废档案资料管理
     */
    @RequiresPermissions("yf:archives:add")
    @Log(title = "医废档案资料管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YfArchives yfArchives)
    {
        return toAjax(yfArchivesService.insertYfArchives(yfArchives));
    }

    /**
     * 修改医废档案资料管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        YfArchives yfArchives = yfArchivesService.selectYfArchivesById(id);
        mmap.put("yfArchives", yfArchives);
        return prefix + "/edit";
    }

    /**
     * 修改保存医废档案资料管理
     */
    @RequiresPermissions("yf:archives:edit")
    @Log(title = "医废档案资料管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YfArchives yfArchives)
    {
        return toAjax(yfArchivesService.updateYfArchives(yfArchives));
    }

    /**
     * 删除医废档案资料管理
     */
    @RequiresPermissions("yf:archives:remove")
    @Log(title = "医废档案资料管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(yfArchivesService.deleteYfArchivesByIds(ids));
    }
}
